package org.edu.model;



import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
/**
 * <h2>权限表</h2>
 * <p>改实例讲解了 <br>角色与权限的 many-to-many 关系<br> 
 * 并写明了配置要点</p>
 * @author 谢圣强
 * @version 1.1
 * @see Role
 */

@Entity
@Table(name = "T_purview")
public class Purview {
	private int id; // 编号
	private int pid; // 父节点
	private String name; //内容
	private boolean open=true; //节点是否展开
	private boolean checked=false;//节点的checkde 是否选中
	
	@Override
	public String toString() {
		String s="{\'id\':" + id + ",\'pId\':" + pid + ",\'name\':\'" + name + "\',\'open\':"+open;
		if(checked){
			s+=",\'checked\':"+checked;
		}
		s+="}";
		return s;
	}
	
	@Id
	@GenericGenerator(name = "idGenerator", strategy = "assigned")
	@GeneratedValue(generator = "idGenerator")
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(name = "tb_pid", nullable = true)
	public int getPid() {
		return pid;
	}

	public void setPid(int pid) {
		this.pid = pid;
	}

	
	@Column(name = "tb_name", nullable = true)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	@Transient
	public boolean isOpen() {
		return open;
	}

	public void setOpen(boolean open) {
		this.open = open;
	}
	@Transient
	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Purview other = (Purview) obj;

		if (id != other.id)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (pid != other.pid)
			return false;
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + pid;
		return result;
	}

	
	
//	public static void main(String[] args) {
//		HashSet<Purview> appleSet=new HashSet<Purview>();
//		Purview p= new Purview();
//		p.setId(1);
//		p.setPid(2);
//		p.setName("aaa");
//		p.setChecked(false);
//		appleSet.add(p);
//		System.out.println(appleSet);
//		Purview p2= new Purview();
//		p2.setId(1);
//		p2.setPid(2);
//		p2.setName("aaa");
//		p2.setChecked(true);
//		appleSet.add(p2);
//		System.out.println(appleSet);
//	}
	
	
}
